-- Copyright (c) Huoty, All rights reserved
-- Author: Huoty <sudohuoty@gmail.com>
-- CreateTime: 2019-06-03 23:25:26

local inspect = require("inspect")

local Person = {
    height = 0,
    weight = 0,
    age = 0,
    sex = 'male',

    _sex_set = { male = true, female = true },
}

function Person:new(obj)
    obj = obj or {}
    setmetatable(obj, self)
    self.__index = self

    obj:check_sex()

    return obj
end

function Person:check_sex()
    assert(self._sex_set[self.sex], 'sex must be a or b')
end


local p1 = Person:new()
local p2 = Person:new{height=170, weight=135, age=28, sex='male'}
print(p1.height)
print(p2.height)

-- local p3 = Person:new{height=170, weight=135, age=28, sex='male_'}


local Student = Person:new{grade=1}

function Student:learn()
    print("learning...")
end


local Programer = Person:new{company='google'}

function Programer:work()
    print("working...")
end


Student:new():learn()
Programer:new():work()
